#ifndef __OS_MSG_QUEUE_H
#define __OS_MSG_QUEUE_H


#include "os_core.h"
#include <stdint.h>


#ifdef __cplusplus
extern "C" {
#endif

typedef volatile struct os_msg_queue OS_MSG_QUEUE_MEMORY
{
    uint8_t *buffer;          // Pointer to the message buffer
    uint16_t size;            // Size of the message buffer
    uint16_t head;            // Head index for the queue
    uint16_t tail;            // Tail index for the queue
    uint16_t count;           // Current number of messages in the queue
}os_msg_queue_st;

#define OS_MSG_QUEUE_INIT(buffer, size) {buffer, size, 0, 0}
#define os_queue_receive_msg(queue, p_msg, len, timeout_ms, p_ret) OS_TASK_WAIT_TIMEOUT(os_msg_queue_try_receive(queue, p_msg,len) == 0, timeout_ms, p_ret)

extern int os_msg_queue_init(os_msg_queue_st  * const queue, uint8_t *buffer, uint16_t size);
extern int os_msg_queue_send(os_msg_queue_st  * const queue, const uint8_t * p_msg, uint16_t len);
extern int os_msg_queue_try_receive(os_msg_queue_st  * const queue, uint8_t *msg,uint16_t len);


#ifdef __cplusplus
}
#endif
#endif
